{template 'tpl_header'}
<div class="bg-color">
    <div class="single-row">
        <div class="single-title">
            <div class="single-title_content">
                {$goods['name']}
            </div>
        </div>
        <div class="single-info">
            <div class="single-img">
                <img src="{php echo tomedia($goods['thumb'])}" alt="">
            </div>
            <div class="single-detail">
                <div class="single-detail_info">
                    <div class="single-detail_info_row">
                        <span class="single-detail_info_row_title">出行日期：</span>{$date}
                    </div>
                    {if !empty($sku['name']) }
                    <div class="single-detail_info_row">
                        <span class="single-detail_info_row_title">具体时间：</span>{$sku['name']}
                    </div>
                    {/if}
                    <div class="single-detail_info_row">
                        <span class="single-detail_info_row_title">出游人数：</span>{$tour_str}
                    </div>
                    <!--<div class="single-detail_info_row">
                        <span class="single-detail_info_row_title">订单号：</span>03459345983453045
                    </div>-->
                </div>
            </div>
            <div class="clear"></div>
        </div>
    </div>
</div>
{if $adult_number != 0 }
<div class="body_style_1">
    <div class="weui-panel weui-panel_access">
        <div class="weui-cell">
            <div class="weui-cell__bd">
                <p>成人旅客</p>
            </div>
            <div class="weui-cell__ft">

            </div>
        </div>
        {loop $adult $ad}
        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">成人{$ad}</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input adult_input" type="text" value="" placeholder="请输入中文姓名">
            </div>
        </div>
        {/loop}
    </div>
</div>
{/if}
{if $child_number != 0 }
<div class="body_style_1">
    <div class="weui-panel weui-panel_access">
        <div class="weui-cell">
            <div class="weui-cell__bd">
                <p>儿童旅客</p>
            </div>
            <div class="weui-cell__ft">

            </div>
        </div>
        {loop $child $ch}
        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">儿童{$ch}</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input child_input" type="text" value="" placeholder="请输入中文姓名">
            </div>
        </div>
        {/loop}
    </div>
</div>
{/if}
{if $baby_number != 0 }
<div class="body_style_1">
    <div class="weui-panel weui-panel_access">
        <div class="weui-cell">
            <div class="weui-cell__bd">
                <p>婴儿旅客</p>
            </div>
            <div class="weui-cell__ft">

            </div>
        </div>
        {loop $baby $ba}
        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">婴儿{$ba}</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input baby_input" type="text" value="" placeholder="请输入中文姓名">
            </div>
        </div>
        {/loop}
    </div>
</div>
{/if}

<div class="body_style_1">
    <div class="weui-panel weui-panel_access">
        <div class="weui-cell">
            <div class="weui-cell__bd">
                <p>联系人信息</p>
            </div>
            <div class="weui-cell__ft">

            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">中文姓名</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" name="contact_name" type="text" value="{$member['real_name']}" placeholder="与证件姓名一致">
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">手机号码</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" name="contact_mobile" type="number" value="{$member['mobile']}" placeholder="请输入手机号码">
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">邮箱</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" name="contact_email" type="email" value="{$member['email']}" placeholder="请输入邮箱">
            </div>
        </div>
    </div>
</div>
<div class="weui-footer">
    <p class="weui-footer__links">
        <a href="javascript:void(0);" class="weui-footer__link open-popup" data-target="#half">查看详细</a>
    </p>
</div>

<a id="half" class='weui-popup__container popup-bottom close-popup'>
    <div class="weui-popup__overlay"></div>
    <div class="weui-popup__modal">
        <div class="toolbar">
            <div class="toolbar-inner" style="background-color: #11a4c0;">
                <div class="pay-title">
                    <p>费用详细</p>
                </div>
                <div class="pay-price"><span class="pay-price_left">共</span><span class="pay-price_right">￥{$goods['total_amount']}</span>
                </div>
            </div>
        </div>
        <div class="modal-content">
            <div class="weui-grids" style="padding: 15px .5rem 30px .5rem">
                {if $adult_number != 0 }
                <div class="pay-price_content">
                    <div class="pay-price_content_title">
                        成人
                    </div>
                    <div class="pay-price_content_desc">
                        {$adult_number} x {php echo number_format($goods['adult_price'],2)}
                    </div>
                </div>
                <div class="clear"></div>
                {/if}
                {if $child_number != 0 }
                <div class="pay-price_content">
                    <div class="pay-price_content_title">
                        儿童
                    </div>
                    <div class="pay-price_content_desc">
                        {$child_number} x {php echo number_format($goods['child_price'],2)}
                    </div>
                </div>
                <div class="clear"></div>
                {/if}
                {if $baby_number != 0 }
                <div class="pay-price_content">
                    <div class="pay-price_content_title">
                        婴儿
                    </div>
                    <div class="pay-price_content_desc">
                        {$baby_number} x {php echo number_format($goods['baby_price'],2)}
                    </div>
                </div>
                <div class="clear"></div>
                {/if}
            </div>
        </div>
    </div>
</a>

<div class="nav-seize-seat"></div>
<div class="nav-price">
    <div class="nav-price_info">
        <span class="nav-price_info_title">总额：</span><span class="nav-price_info_price">￥{$goods['total_amount']}</span>
    </div>
    <div class="nav-price_button">
        <a id="payment" class="weui-btn weui-btn_mini weui-btn_primary" style="margin-top: 0">立即购买</a>
    </div>
    <div class="clear"></div>
</div>
{template 'tpl_footer'}
<script type="text/javascript" src="{$_W['siteroot']}app/resource/js/lib/mui.min.js"></script>
<script type="text/javascript" src="{$_W['siteroot']}app/resource/js/app/util.js"></script>
<script>
    var is_pay_look = false;
    var adult_number = '{$adult_number}';
    var child_number = '{$child_number}';
    var baby_number = '{$baby_number}';
    $(function () {
        FastClick.attach(document.body);

        $('#payment').click(function () {
            if(!is_pay_look){
                //防止重复提交
                is_pay_look = true;
                var adult = [];
                var child = [];
                var baby = [];
                if(adult_number != '0'){
                    var is_fales = false;
                    var adult_input = $('.adult_input');
                    adult_input.each(function(){
                        if($(this).val() == ''){
                            is_fales = true;
                            adult = [];
                            return false;
                        }
                        adult.push($(this).val());
                    });
                    if(is_fales){
                        is_pay_look = false;
                        $.toast('请完善成人旅客信息', "cancel");
                        return false;
                    }
                }

                if(child_number != '0'){
                    var is_fales = false;
                    var child_input = $('.child_input');
                    child_input.each(function(){
                        if($(this).val() == ''){
                            is_fales = true;
                            child = [];
                            return false;
                        }
                        child.push($(this).val());
                    });
                    if(is_fales){
                        is_pay_look = false;
                        $.toast('请完善儿童旅客信息', "cancel");
                        return false;
                    }
                }

                if(baby_number != '0'){
                    var is_fales = false;
                    var baby_input = $('.baby_input');
                    baby_input.each(function(){
                        if($(this).val() == ''){
                            is_fales = true;
                            baby = [];
                            return false;
                        }
                        baby.push($(this).val());
                    });
                    if(is_fales){
                        is_pay_look = false;
                        $.toast('请完善儿童旅客信息', "cancel");
                        return false;
                    }
                }

                var contact_name = $('input[name="contact_name"]').val();
                var contact_mobile = $('input[name="contact_mobile"]').val();
                var contact_email = $('input[name="contact_email"]').val();
                if (contact_name == '') {
                    is_pay_look = false;
                    $.toast('请填写联系人', "cancel");
                    return false;
                }

                if (contact_mobile == '') {
                    is_pay_look = false;
                    $.toast('请填写联系人手机', "cancel");
                    return false;
                }

                if (contact_email == '') {
                    is_pay_look = false;
                    $.toast('请填写联系人邮箱', "cancel");
                    return false;
                }

                var myreg = /^[1][3-8][0-9]{9}$/;
                if (!myreg.test(contact_mobile)) {
                    is_pay_look = false;
                    $.toast('请填写有效的手机号码', "cancel");
                    return false;
                }
                var reg = new RegExp("^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$");
                if (!reg.test(contact_email)) {
                    is_pay_look = false;
                    $.toast('请填写有效的邮箱', "cancel");
                    return false;
                }

                //异步生成订单
                var data = {
                    'action': 'add_payment_order',
                    'goods_id': '{$id}',
                    'type' : '{$type}',
                    'departure_date' : '{$date}',
                    'adult_number' : '{$adult_number}',
                    'child_number' : '{$child_number}',
                    'baby_number' : '{$baby_number}',
                    'adult_members': adult,
                    'child_members': child,
                    'baby_members': baby,
                    'contact_name' : contact_name,
                    'contact_mobile' : contact_mobile,
                    'contact_email' : contact_email,
                    'sku_id' : '{$sku_id}'
                };
                $.ajax({
                    url: "{php echo $this->createMobileUrl('ajax')}",
                    type: 'post',
                    data: data,
                    dataType: 'json',
                    success: function (res) {
                        if (res.status == 1) {
                            var data = res.data;
                            util.pay({
                                orderFee : data.total_price,
                                payMethod : 'wechat',
                                orderTitle : data.name,
                                orderTid : data.order_no,
                                module : 'vj_bontrip',
                                type : '{$type}',
                                success : function(result) {
                                    $.toast('支付成功');
                                    window.location.href = "{php echo $this->createMobileUrl('me'); }";
                                },
                                fail : function(result) {
                                    $.toast(result.message, "cancel");
                                    is_pay_look = false;
                                },
                                complete : function(result) {
                                }
                            });

                        } else {
                            is_pay_look = false;
                            $.toast(res.msg, "cancel");
                        }

                    },
                    error: function (res) {
                        is_pay_look = false;
                        $.toast('请求失败，请检测网络或联系客服', "cancel");
                    }
                });

            }
        });
    });
    $(document).on("open", ".weui-popup-modal", function () {
        console.log("open popup");
    }).on("close", ".weui-popup-modal", function () {
        console.log("close popup");
    });

</script>